// 初始化全局状态管理
const stateX = new StateX({
    state: {
        userInfo: {}
    },
    set: {
        setUserInfo(key, data, state) {
            state = data
            return this.state
        }
    },
    get: {
        getUserInfo (key, state) {
            return new Promise((resolve, reject) => {
                if (state.uid !== undefined) resolve(state)
                getUserInfo().then(res => {
                    if (res.code === 200) {
                        if (res.items.user_cover === '1') res.items.user_cover = '/static/cms/images/space@background.webp'
                        else res.items.user_cover = `/cms/api/community/tool/get_file/${res.items.user_cover}`
                        res.items.avatar = `/cms/api/community/tool/get_file/${res.items.avatar}`
                    } else {
                        Cookies.remove('authorization')
                        res.items.user_cover = 'https://blog.mzshe.cn/wp-content/themes/kratos-pjax-0.2.9/images/thumb/thumb_6.jpg'
                        res.items.nick_name = '我的主页'
                    }
                    this.emit(key, res.items)
                    resolve(res.items)
                })
            })
        }
    }
})

layui.use('util', function(){
    var util = layui.util;
    //执行
    util.fixbar({
    });
});
